﻿using System;
using System.Collections.Generic;

namespace TestByWire
{
    internal class DynamicDeclarations
    {
        [ThreadStatic]
        private static List<IContainerInteraction> _dynamicContainerInteractions;

        internal static void Reset()
        {
            _dynamicContainerInteractions = new List<IContainerInteraction>();
        }

        internal static void AddContainerInteraction(IContainerInteraction containerInteraction)
        {
            if (containerInteraction == null)
            {
                throw new ArgumentNullException("containerInteraction");
            }

            _dynamicContainerInteractions.Add(containerInteraction);
        }

        internal static IContainerInteraction[] GetDynamicInteractions()
        {
            return _dynamicContainerInteractions.ToArray();
        }

		public static void ReplaceContainerInteraction(IContainerInteraction replace, IContainerInteraction with)
    	{
    		if (replace == null)
    		{
    			throw new ArgumentNullException("replace");
    		}

    		if (with == null)
    		{
    			throw new ArgumentNullException("with");
    		}

			int replaceIndex = _dynamicContainerInteractions.IndexOf(replace);
			_dynamicContainerInteractions[replaceIndex] = with;
    	}
    }
}
